#include "SearchForBallBehaviour.h"

//hlada loptu na ihrisku
void SearchForBallBehaviour::Behave()
{
	int nSimTime = world->state->GetSimTime();
	int nPlayerNumber = world->me->GetUniform();
	
	world->me->bNeckSynchronization = false;		
	int nTimeWithoutBallInfo =  world->state->GetSimTime() - DATA_STORAGE.lastValidBallTime;

	// 1. cyklus - neviem, kde je lopta, pozrem sa tam, kde som ju videl naposledy 
	if(nTimeWithoutBallInfo == 1)
	{
		GetTurnNeckToBehaviour()->Behave(DATA_STORAGE.lastValidBallInfo->pos + DATA_STORAGE.lastValidBallInfo->vel, 
			world->me->pos + world->me->vel);
		GetTurnNeckToBehaviour()->NeckSynchronizationWithVI(NOR_VIEW);
		DATA_STORAGE.SetNextSynchMode(Synch_Normal);
		return;
	}
	// 2. cyklus - tento cyklus nerobim nic, lebo cakam na VI
	else if(nTimeWithoutBallInfo == 2)
	{
		return;
	}
	// 3. cyklus - VI, asi dosla, ale nebola tam informacia o pozicii lopty, preto sa otocim na dane miesto a zvacsim pohlad 
	else if(nTimeWithoutBallInfo == 3)
	{
		GetTurnToBehaviour()->Behave(DATA_STORAGE.lastValidBallInfo->pos + DATA_STORAGE.lastValidBallInfo->vel);
		GetAlignNeckBehaviour()->Behave();
		return;
	}
	else if(nTimeWithoutBallInfo == 4)
	{
	}

	else
	{
		GetScanBehaviour()->Behave();
	}	
}
